-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method for native watcher initialization with fallback #441
Conversation
This is a draft because:
Todo:
CC @samuelcolvin as possible consumer |
4fad052
to
d539e4c
Compare
I'd call it a breaking change if it changes behavior.
I think it's totally fine while we have
These could come later :)
I don't have a strong opinion on that, maybe we could prepare an optional value?
Hmm, that sounds like a rather difficult issue and I cannot prepare a solution for that soon (I'm now fixing my dev env and cannot check your code deeply). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broadly seems fine to me, I'll probably stick with that I have now in watchfiles though since it's working well.
#[allow(unused)] | ||
ErrorKind::Io(io_error) => { | ||
#[cfg(target_os = "linux")] | ||
if io_error.raw_os_error() == Some(38) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a documented meaning to 38 or indeed other codes somewhere? I suspect we should fallback in more cases but I have no idea how to find out which ones should be an error and which should fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, here is the manpage though I prefer this list
Problem is that this does not tell us which of these could be emitted by our specific syscall.
|
||
impl WatcherFallback { | ||
/// Returns the watcher inside | ||
pub fn take_boxed(self) -> Box<dyn Watcher>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I would prefer that this implemented watch
. Is that very verbose/difficult?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a very good idea! and it would make the enum more worthwhile (because otherwise I don't actually see much of a value over directly boxing it, except for claiming the allocation-free throne, while not being useful at all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I tried this.. And it gets awkward.
- We can't implement
Watcher::new
due to missingCopy
/Clone
onevent_handler
. - We can't implement a real
kind()
, as we don't have access toself
. This kind of API is specifically not designed for runtime-selected watchers it seems. (V6 incoming.. ) We could still implement the functions without the trait, or leave themunimplemented!()
for the new and the additional watcher-kind as in my new code.
Edit: But we can implement Deref
and DerefMut
, allowing direct Watcher::
* access, but also kind(&self)
, which isn't the Trait, but at least gives the functionality.
Please review again, the addition of Deref/DerefMut allows direct access to the watcher in our enum, making the whole stack allocation worthwhile, such that boxing is not required. Example Open Questions:
|
How about |
Why was this closed? |
Ads a new method for initializing the recommended watcher and falling back to pollwatcher on failure to do so
Fixes #423